Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The deployed frontend at
https://pages.opencodingsociety.comwas getting Mixed Content errors when calling the Spring backend athttps://spring.opencodingsociety.com.Root Cause
Commit
2e98f9f("fix login security issues - cookie switching across platforms") introducedrequest.isSecure()checks to determine cookie flags. Behind the Nginx reverse proxy, the connection from Nginx → Spring is plain HTTP (proxy_pass http://localhost:8587), sorequest.isSecure()always returnsfalse.This caused:
Secure=falseon JWT cookies → browsers reject them over HTTPS cross-originSameSite=Laxinstead ofNone→ blocks cross-origin cookie sending frompages.opencodingsociety.comhttp://redirect URLs → browser blocks as Mixed ContentError seen in browser console
Fix
1. Use config values directly instead of
request.isSecure()(Java)Files:
JwtApiController.java,MvcSecurityConfig.javaReplaced all occurrences of:
With direct use of config values:
Cookie flags are now driven entirely by
application.properties:jwt.cookie.secure=true,jwt.cookie.same-site=None(already set).envwithjwt.cookie.secure=false,jwt.cookie.same-site=Lax2. Trust forwarded headers from Nginx (application.properties)
Added:
server.forward-headers-strategy=frameworkThis tells Spring to read
X-Forwarded-Proto,X-Forwarded-Host, etc. from the reverse proxy, so redirect URLs are generated withhttps://.3. Forward HTTPS headers in Nginx (nginx_file)
Added:
Files Changed
src/main/java/com/open/spring/security/JwtApiController.javarequest.isSecure()from/authenticateand/api/logoutcookie builderssrc/main/java/com/open/spring/security/MvcSecurityConfig.javarequest.isSecure()from login success handler and logout handler cookie builderssrc/main/resources/application.propertiesserver.forward-headers-strategy=frameworknginx_fileX-Forwarded-Proto/Host/Port/Forproxy headersDeployment Steps
sudo nginx -s reload